<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>搜索结果</title>
    <%- include('../../_global/baseLibs') %>

    <style>
        .result-content-box > ul > li {
            border-bottom:1px solid #cfcfcf;
            bottom: 0;
         }

    </style>
    <script>
        $(function(){
            initData();
            initView();
        })
       function initView() {
           //跳转到主页
           $(".qx-text").click(function(){
               var json = {
                   url: "/html/gzd/index.ejs",
                   title: "",
                   app_user_agent: "index",
                   type: "indexSearch",
                   animate:"pop",
               }
               $.QuickUrlUtils.redirectJSBridge(json);


           });

            $(".xgyy-box .text-right").click(function(){
                $.pageSwitch.goToUrl("myOrder","searchYy");
            });
       }
       
        function initData (){
            //初始化页面
            initYm();
            var text = StoreCache.getCache("searchText");
            $(".input-search").val(text);
             $.QuickRemote.AjaxJson({
                funcName: "/api/gzd/yygh/getHospitalList"
                ,params: {pageNum:"1",pageSize:"10",hosname:text}
                ,callback:querySearchYyHandler
            });
        }
        //医院查询
        function querySearchYyHandler(result){
            var json = result.hospitals;
            if(!StringUtils.isEmpty(json)){
                $(json).each(function (index,item) {
                    var value = item["distance"];
                    if(value == "" || value == null){
                        value = "0";
                    }
                    var yyxx = $($("#YY_HTML").html());
                    yyxx.find("a").click(function(){
                        StoreCache.setCache("YYGH_HOSINFO", item);
                        $.pageSwitch.goToUrl("myOrder","hosDetail","hosCode="+item["hosCode"]);
                    });
                    if(item.hosImgUrl && item.hosImgUrl!=""){
                       yyxx.find(".hospital-icon").css({"background":"url('"+item.hosImgUrl+"') no-repeat"}); 
                    }
                    
                    yyxx.find(".text-box").find("span").html(item.hosName);
                    yyxx.find("span").eq(1).html(getHosGrade(item["hosGrade"])+getHosLevel(item["hosLevel"]));
                    yyxx.find("span").eq(2).html(getIsMedicare(item.isMedicare));
                    yyxx.find("span").eq(3).html(item.doctorCount+" 医生");
                    yyxx.find("span").eq(4).html(value+" m");
                    $(".xgyy-box ul").append(yyxx);
                })
            }else{
                $(".xgyy-box").hide();
            }
        }

        function initYm() {
            //初始化
            //在线咨询
            //$(".consult-box").show();
            //$(".consult-list-box").show();
            //$(".consult-list-box ul").html("");
            //医生
            $(".member-box").show();
            $(".member-box ul").html("");
            //医院
            $(".xgyy-box").show();
            $(".xgyy-box ul").html("");
            //疾病自查
            $(".result-content-box").show();
            $(".result-content-box ul").html("");
        }
        /**获取医院等级*/
        function getHosLevel(hosLevel){
            var value = "";
            if(hosLevel == "0"){
                value = "特等";
            }
            else if(hosLevel == "1"){
                value = "甲等";
            }
            else if(hosLevel == "2"){
                value = "乙等";
            }
            else if(hosLevel == "3"){
                value = "丙等";
            }
            return value;
        }

        /**判断是否是医保*/
        function getIsMedicare(medicare){
            var value = "";
            if(medicare == "0"){
                value = "医保";
            }
            else //if(medicare == "1")
            {
                value = "非医保";
            }
            return value;
        }

        /**获取医院级别*/
        function getHosGrade(hosGrade){
            var value = "";
            if(hosGrade == "0"){
                value = "社区卫生服务中心";
            }
            else if(hosGrade == "1"){
                value = "一级医院";
            }
            else if(hosGrade == "2"){
                value = "二级医院";
            }
            else if(hosGrade == "3"){
                value = "三级医院";
            }
            else if(hosGrade == "3"){
                value = "未评级";
            }
            return value;
        }

        //添加历史记录
        function addCache(text){
            var cache = StoreCache.getCache("searchCache");
            var ary = [];
            ary.push(text);
            if(!StringUtils.isEmpty(cache)){
                cache = $.grep(cache, function(num,index){
                    if(num != text){
                        return num;
                    }
                });
                $(cache).each(function(index){
                    if(index<4){
                        ary.push(this);
                    }
                });
            }
            StoreCache.setCache("searchCache", ary);
        }
        function searchbut(){
            var text = $(".input-search").val();
            if(!StringUtils.isEmpty(text)) {
                addCache(text);
                StoreCache.setCache("searchText",text);
                initData();
                initView();
               /* $.QuickUrlUtils.redirectJSBridge({
                    url: "/plat/search/searchResult.html" ,
                    title: "搜索结果",
                    app_user_agent: "search"
                });*/
            }
        }
    </script>
</head>
<body>
<section class="page-wrap search-result">
    <header class="header-search fixed">
        <aside class="header-content">
            <div class="search-bar-box">
                <div class="input-search-box" href="javascript:void(0);">
                    <input class="input-search"  style="width:calc(100% - 110px);margin-bottom: 10px;" placeholder="请输入搜索内容" />
                    <i class="fdj-icon search-text" onclick="searchbut()">搜索</i>
                    <!-- <a class="close-btn" href="javascript:history.back()">返回</a> -->
                    <a class="qx-text">取消</a>
                </div>
            </div>
        </aside>
    </header>
    <div class="result-content-box">
        <ul>
        </ul>
    </div>
    <!--<div class="consult-box">-->
        <!--<span class="text-left">相关咨询</span>-->
        <!--<span class="text-right">更多<i class="arrow-right"></i></span>-->
    <!--</div>-->
    <!--<div class="consult-list-box">-->
        <!--<ul>-->
            <!--<li>-->
                <!--<span class="wen-icon">问</span>-->
                <!--<div class="text-box">-->
                    <!--最近天气特别炎热,家里开了空调。孩子晚上踢被子,就着凉感冒了。-->
                    <!--这几天一直在流鼻涕,鼻涕是比较清的那种,一直在流,给他喝了感冒-->
                    <!--冲剂也没用。-->
                <!--</div>-->
            <!--</li>-->
        <!--</ul>-->

    <div class="xgyy-box">
        <div class="xgyy-title">
            <span class="blue-title">相关医院</span>
            <span class="text-right">更多<i class="arrow-right"></i></span>
        </div>
        <div class="doctor-list-box">
            <ul>
            </ul>
        </div>
    </div>
</section>
</body>
<script type="text/html" id="JB_HTML">
    <li>
        <a href="javascript:void(0);" style="color: #3a3840">
            <span class="title">感冒</span>
            <p><span class="text-left">就诊科室：</span><span>呼吸内科</span></p>
            <p><span class="text-left">常见症状：</span><span>喷嚏，鼻塞，流清水样鼻涕。</span></p>
        </a>
    </li>
</script>
<script type="text/html" id="ZX_HTML">
    <li>
        <a href="javascript:void(0);" style="color: #3a3840">
            <span class="wen-icon">问</span>
            <div class="text-box">
            最近天气特别炎热,家里开了空调。孩子晚上踢被子,就着凉感冒了。
            这几天一直在流鼻涕,鼻涕是比较清的那种,一直在流,给他喝了感冒
            冲剂也没用。
            </div>
        </a>
    </li>
</script>
<script type="text/html" id="YS_HTML">
    <li>
        <a>
            <img src="/web/images/doctor2.png">
            <div class="text-box">
                <h4 class="h4-title">
                    <span class="name">陆爱珍</span>
                    <span>全科</span>
                    <span>副主任医师</span>
                </h4>
                <p>南京万达医院</p>
            </div>
            <div class="item-after"><i class="iconfont icon-more"></i></div>
        </a>
    </li>
</script>

<script type="text/html" id="YY_HTML">
    <li>
        <a href="javascript:void(0);">
            <i class="hospital-icon"></i>
            <div class="text-box">
                <p>
                    <span class="title-text">长征医院</span>
                    <span class="yellow-text">三甲</span>
                    <span class="yellow-text">医保</span>
                </p>
                <p>
                    <span>2089 医生</span>
                    <span class="gray-text">6km</span>
                </p>
            </div>
            <div class="item-after"><i class="iconfont icon-more"></i></div>
        </a>
    </li>
</script>
</html>